package com.xhh.nphm.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xhh.nphm.system.domain.IsGoBackConfig;
import org.apache.ibatis.annotations.*;

@Mapper
public interface IsGoBackConfigDao extends BaseMapper<IsGoBackConfig> {
    @Delete("delete tm_noGoBack_dept where confDeptId = #{deptId} ")
    int deleteDeptConfByDeptId(Long deptId);

    @Insert("insert into tm_noGoBack_dept(confDeptId,noGoBackDeptId) values(#{deptId},#{noGoBackDeptId}) ")
    int insertDeptConf(@Param("deptId") Long deptId, @Param("noGoBackDeptId") String noGoBackDeptId);

    @Select("select noGoBackDeptNames = stuff((select '，'+deptName from bUserDept b1 ,tm_noGoBack_dept b2 where b2.noGoBackDeptId = b1.NoUnit and b2.confDeptId = #{deptId} for xml path('')) , 1 , 1 , '')")
    String selectNoGoBackDeptNames(Long deptId);

    @Select("select count(1) from tm_noGoBack_dept where confDeptId=#{sdeptId} and noGoBackDeptId = #{sbdeptId} ")
    int checkPeerDeptIsGoBack(@Param("sdeptId") String sdeptId,@Param("sbdeptId") String sbdeptId);

    @Select("select pkId,deptId,deptName,isAll,optId,optName,optTime,isAllow from tm_isGoBackConf where deptId = #{deptId} ")
    IsGoBackConfig selectConfByDept(@Param("deptId")Long deptId);

    @Select("select count(1) from tm_isGoBackConf t1, tm_noGoBack_dept t2 where t1.deptId = t2.confDeptId  and t1.isAllow = 1 and t2.noGoBackDeptId = #{deptId} ")
    int checkIsGoBackByDeptId(@Param("deptId")Long deptId);
}
